using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class NameMap : EntityTypeConfiguration<Name>
    {
        public NameMap()
        {
            // Primary Key
            this.HasKey(t => t.USERID);

            // Properties
            this.Property(t => t.USERNAME)
                .IsRequired()
                .HasMaxLength(15);

            this.Property(t => t.PASSWORD)
                .HasMaxLength(20);

            this.Property(t => t.FULLNAME)
                .HasMaxLength(30);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            this.Property(t => t.DefPhys)
                .HasMaxLength(6);

            this.Property(t => t.Code)
                .HasMaxLength(50);

            this.Property(t => t.Names_RecordType)
                .HasMaxLength(20);

            this.Property(t => t.Names_RecordID)
                .HasMaxLength(20);

            this.Property(t => t.NM_Per_DefSeq)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Names");
            this.Property(t => t.USERNAME).HasColumnName("USERNAME");
            this.Property(t => t.PASSWORD).HasColumnName("PASSWORD");
            this.Property(t => t.USERID).HasColumnName("USERID");
            this.Property(t => t.FULLNAME).HasColumnName("FULLNAME");
            this.Property(t => t.USERTYPE).HasColumnName("USERTYPE");
            this.Property(t => t.DISABLEUSER).HasColumnName("DISABLEUSER");
            this.Property(t => t.DEFCSTCTR).HasColumnName("DEFCSTCTR");
            this.Property(t => t.ROOTCSTCTR).HasColumnName("ROOTCSTCTR");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");
            this.Property(t => t.LANGUAGE).HasColumnName("LANGUAGE");
            this.Property(t => t.DefPhys).HasColumnName("DefPhys");
            this.Property(t => t.showtips).HasColumnName("showtips");
            this.Property(t => t.tipnb).HasColumnName("tipnb");
            this.Property(t => t.TPI).HasColumnName("TPI");
            this.Property(t => t.Code).HasColumnName("Code");
            this.Property(t => t.Names_RecordType).HasColumnName("Names_RecordType");
            this.Property(t => t.Names_RecordID).HasColumnName("Names_RecordID");
            this.Property(t => t.NM_PER_EnablePerio).HasColumnName("NM_PER_EnablePerio");
            this.Property(t => t.NM_Per_ChartByDef).HasColumnName("NM_Per_ChartByDef");
            this.Property(t => t.NM_DC_Maximize).HasColumnName("NM_DC_Maximize");
            this.Property(t => t.NM_Per_DefSeq).HasColumnName("NM_Per_DefSeq");
            this.Property(t => t.NM_ShowToolboxHints).HasColumnName("NM_ShowToolboxHints");
            this.Property(t => t.NM_LastManager).HasColumnName("NM_LastManager");
            this.Property(t => t.NM_DisablePostVbatch).HasColumnName("NM_DisablePostVbatch");
            this.Property(t => t.NM_DisablePostVbatchSDate).HasColumnName("NM_DisablePostVbatchSDate");

            // Relationships
            this.HasOptional(t => t.UserType1)
                .WithMany(t => t.Names)
                .HasForeignKey(d => d.USERTYPE);

        }
    }
}
